package com.shared.controller;

import com.shared.dao.PCouponMapper;
import com.shared.pojo.PCoupon;
import com.shared.server.PCouponServer;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Controller
public class PCouponController {

    @Autowired
    private PCouponMapper pCouponMapper;
    @Autowired
    private PCouponServer pCouponServer;

    @GetMapping("/coupon/{userid}")
    @ResponseBody
    @ApiOperation(value = "根据用户id查询优惠券(可用)")
    public List<PCoupon> findByUserid(@PathVariable("userid") Integer userid) {
        return pCouponServer.findByUserid(userid);
    }

    @GetMapping("/pon/{userid}")
    @ResponseBody
    @ApiOperation(value = "根据用户id查询优惠券(已失效)")
    public List<PCoupon> findByUserId(@PathVariable("userid") Integer userid) {
        return pCouponServer.findByUserId(userid);
    }

    @DeleteMapping("/deletecoupon/{id}")
    @ResponseBody
    @ApiOperation(value = "根据id删除优惠券")
    public void deletecoupon(@PathVariable("id") Integer id) {
        this.pCouponServer.deletecoupon(id);
    }
}
